import java.sql.Date;
import java.util.Calendar;

public class ClientMain {

	public static void main(String[] args) {

		// Get MBank Instance
		MBank mBank = null;

		try {
			mBank = MBank.getInstance();
		} catch (DBManagerException e1) {
			e1.printErrMsg();
		}

		// Client Login
		ClientActions clientActions = mBank.clientLogin(25, 565844);

		if (clientActions == null) {

			System.out.println("[ClientMain]: Invalid Client Password.");

		} else {

			System.out.println("[ClientMain]: ClientActions object received.");

			// Withdraw funds from account
			System.out.println("[ClientMain]: Withdraw funds from account.");
			Account account2;
			try {
				account2 = clientActions.getAccountById(25);
				clientActions.withdraw(account2, 15000);
			} catch (DBManagerException e) {
				e.printErrMsg();
			}

			// Deposit funds to account
			Account account1;
			try {
				account1 = clientActions.getAccountById(25);
				clientActions.deposit(account1, 20000);
				System.out.println("[ClientMain]: Add funds to Account.");
			} catch (DBManagerException e1) {
				e1.printErrMsg();
			}

			// Add deposit
			try {
				Calendar today = Calendar.getInstance();
				Date openningDate = new Date(today.getTimeInMillis());
				today.add(Calendar.DAY_OF_YEAR, 800);
				Date endingDate = new Date(today.getTimeInMillis());
				Deposit deposit = new Deposit(3, 25, openningDate, endingDate, 5000);
				clientActions.addDeposit(deposit);
				System.out.println("[ClientMain]: Add new Deposit.");
			} catch (DBManagerException e) {
				e.printErrMsg();
			}

			// Withdraw Deposit (before end date)
			// try {
			// Deposit deposit3 = clientActions.getDepositById(80);
			// clientActions.drawDeposit(deposit3);
			// } catch (DBManagerException e) {
			// e.printErrMsg();
			// }

		}

		mBank.closeConnection();
	}
}
